import { piniaPersistConfig } from "@/config";
import { defineStore } from "pinia";
import { ref } from "vue";

const key: string = "permission";

export const usePermissionStore = defineStore(
  key,
  () => {
    /**
     * @description 用户权限标识
     */
    const permissions = ref<string[]>([]);

    /**
     * @description 清除权限缓存
     */
    function clearCacheHandler() {
      permissions.value = [];
    }

    return {
      permissions,
      clearCacheHandler
    };
  },
  {
    persist: piniaPersistConfig(key, sessionStorage)
  }
);
